/*
 * @Date: 2020-10-05 16:43:29
 * @LastEditors: Tonser
 * @LastEditTime: 2020-10-05 16:45:06
 * @FilePath: /swarm_ws/src/px4_swarm_control/src/LcmRosNode.h
 * @Description: lcm ros node 管理类
 */
#ifndef INCLUDE_LCMROSNODE_H
#define INCLUDE_LCMROSNODE_H
#include <lcm/lcm-cpp.hpp>
#include <unordered_set>
#include <ros/ros.h>
#include "../../include/LcmMsg/SwarmData_t.hpp"
#define Buffer std::vector<uint8_t>


/***
 * 使用方法 需要自己维护一个队列用于 对实时进入和出去的消息进行更新，其中队列长度可以配置
 * 需要开启对应timer 一快 一慢 的进行数据发送与解析 25帧 和 100帧
 */
class LcmRosNode{
public:
    lcm::LCM lcmManager;
    bool lcmOk = false;
    std::unordered_set<int32_t> sent_msgs;
    static LcmRosNode* getInstance();
    void setLcmManager(std::string &lcm_url,ros::NodeHandle &nh,bool enable_debug_print);
    void sendSwarmDataLcm(Buffer buffer,ros::Time stamp,int id);
private:
    static LcmRosNode *instance;
    bool enable_debug_print = false;
    ros::Publisher lcmRecvBroadcastDataPub;
    LcmRosNode() = default;
    int handle();
    void onSwarmDatalcm(const lcm::ReceiveBuffer *receiveBuffer, const std::string &channal, const SwarmData_t *msg);
};




#endif